'use strict';
/**
 * @bussiness {帖子}
 * @author {JC}
 * @date {2022-09-28}
 * **/
const Controller = require('egg').Controller;
class Posts extends Controller {
    /**@effect {拿取主页帖子信息数据}**/
    async takePostsHome(){
        const {ctx} = this;
        const res = await ctx.service.posts.index.takeHomePosts();
        res.sort(()=>{
            return Math.random()>.5 ? -1 : 1; //打乱帖子 
        })
        ctx.body = {
            status:200,
            data:res.splice(0, 8),
            msg:"200"
        }
    }
    /**@effect {拿取关注的帖子信息数据}**/
    async takeFocusedPost(){
        const {ctx} = this;
        const query  = ctx.request.query
        const res =await ctx.service.posts.index.takeFocusOnPost(query)
        ctx.body = {
            status:200,
            data:res,
            msg:"200"
        }
    }
    /**
     * @effect {拿取选择分类拿到帖子信息数据}
    **/
    async takePostsCateList() {
        const  {ctx} = this;
        const query = ctx.request.query
        const res =await ctx.service.posts.index.takePostsByCate(query)
        ctx.body = {
            status:200,
            data:res,
            msg:"200"
        }
    }
    /**@effect {根据id拿到帖子信息数据}**/
    async takePostsById(){
        const {ctx} = this;
        const query = ctx.request.query;
        const res = await ctx.service.posts.index.takeAPostsById(query);
        ctx.body = {
            status:200,
            data:res,
            msg:"success"
        }
    }
}
module.exports = Posts 